using System;
using System.Windows.Forms;
using ctsu.Shared;

namespace ctsu.Admin.Forms.CoreLab
{
	public class SampleChooser2Dlg : System.Windows.Forms.Form
	{
		private BarScan _barscan;
		//private BarScan.BarScanCompleteHandler _barScanComplete;

		public delegate void SelectSampleButtonClickEventHandler(object sender, SelectSamplesEventArgs e);
		public event SelectSampleButtonClickEventHandler SelectSampleClick;

		private System.Windows.Forms.RadioButton rdoManual;
		private System.Windows.Forms.Button Retrieve;
		private System.Windows.Forms.TextBox Num_ID;
		public System.Windows.Forms.RadioButton rdoBatch;
		private System.Windows.Forms.Label lblNum_ID;
		private System.Windows.Forms.Button btnClose;
		public RadioButton rdoBatchOut;
		private System.ComponentModel.Container components = null;

		public SampleChooser2Dlg()
		{
			InitializeComponent();
			//this._barScanComplete += new BarScan.BarScanCompleteHandler(barScan_Complete);
			this._barscan = new BarScan(this, Num_ID, null);
			this._barscan.BarScanComplete += new ctsu.Shared.BarScan.BarScanCompleteHandler(barScan_Complete);
			this.Num_ID.KeyPress += new KeyPressEventHandler(Forms.Utils.txtNumWholePos_KeyPress);
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.rdoManual = new System.Windows.Forms.RadioButton();
			this.Retrieve = new System.Windows.Forms.Button();
			this.Num_ID = new System.Windows.Forms.TextBox();
			this.rdoBatch = new System.Windows.Forms.RadioButton();
			this.lblNum_ID = new System.Windows.Forms.Label();
			this.btnClose = new System.Windows.Forms.Button();
			this.rdoBatchOut = new System.Windows.Forms.RadioButton();
			this.SuspendLayout();
			// 
			// rdoManual
			// 
			this.rdoManual.Location = new System.Drawing.Point(8, 5);
			this.rdoManual.Name = "rdoManual";
			this.rdoManual.Size = new System.Drawing.Size(152, 21);
			this.rdoManual.TabIndex = 42;
			this.rdoManual.Text = "Manual (or Use Scanner)";
			this.rdoManual.CheckedChanged += new System.EventHandler(this.rdo_CheckedChanged);
			// 
			// Retrieve
			// 
			this.Retrieve.Enabled = false;
			this.Retrieve.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.Retrieve.Location = new System.Drawing.Point(19, 119);
			this.Retrieve.Name = "Retrieve";
			this.Retrieve.Size = new System.Drawing.Size(64, 23);
			this.Retrieve.TabIndex = 45;
			this.Retrieve.Text = "Retrieve";
			this.Retrieve.Click += new System.EventHandler(this.Retrieve_Click);
			// 
			// Num_ID
			// 
			this.Num_ID.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.Num_ID.Location = new System.Drawing.Point(121, 90);
			this.Num_ID.MaxLength = 5;
			this.Num_ID.Name = "Num_ID";
			this.Num_ID.Size = new System.Drawing.Size(40, 20);
			this.Num_ID.TabIndex = 0;
			this.Num_ID.TextChanged += new System.EventHandler(this.Num_ID_TextChanged);
			// 
			// rdoBatch
			// 
			this.rdoBatch.Checked = true;
			this.rdoBatch.Location = new System.Drawing.Point(8, 32);
			this.rdoBatch.Name = "rdoBatch";
			this.rdoBatch.Size = new System.Drawing.Size(150, 21);
			this.rdoBatch.TabIndex = 43;
			this.rdoBatch.Text = "From Test In Batch";
			this.rdoBatch.CheckedChanged += new System.EventHandler(this.rdo_CheckedChanged);
			// 
			// lblNum_ID
			// 
			this.lblNum_ID.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.lblNum_ID.Location = new System.Drawing.Point(6, 90);
			this.lblNum_ID.Name = "lblNum_ID";
			this.lblNum_ID.Size = new System.Drawing.Size(112, 16);
			this.lblNum_ID.TabIndex = 46;
			this.lblNum_ID.Text = "Enter batch number:";
			// 
			// btnClose
			// 
			this.btnClose.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
			this.btnClose.Location = new System.Drawing.Point(91, 119);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new System.Drawing.Size(64, 23);
			this.btnClose.TabIndex = 47;
			this.btnClose.Text = "Close";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// rdoBatchOut
			// 
			this.rdoBatchOut.Location = new System.Drawing.Point(8, 59);
			this.rdoBatchOut.Name = "rdoBatchOut";
			this.rdoBatchOut.Size = new System.Drawing.Size(150, 21);
			this.rdoBatchOut.TabIndex = 48;
			this.rdoBatchOut.Text = "From Test Out Batch";
			// 
			// SampleChooser2Dlg
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(170, 168);
			this.Controls.Add(this.rdoBatchOut);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.rdoManual);
			this.Controls.Add(this.Retrieve);
			this.Controls.Add(this.Num_ID);
			this.Controls.Add(this.rdoBatch);
			this.Controls.Add(this.lblNum_ID);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "SampleChooser2Dlg";
			this.Text = "Select Draw Labels";
			this.ResumeLayout(false);
			this.PerformLayout();

		}
		#endregion

		private void barScan_Complete(object sender, BarScanEventArgs e)
		{
			if (e.ID > -1)
				Retrieve_Click(sender, new System.EventArgs());
		}

		private void Num_ID_TextChanged(object sender, System.EventArgs e)
		{
			if (Num_ID.Text.Length > 0)
			{
				if ((Convert.ToInt32(Num_ID.Text)) > 0)
					Retrieve.Enabled = true;
				else
					Retrieve.Enabled = false;
			}
			else
				Retrieve.Enabled = false;
		}

		private void Retrieve_Click(object sender, System.EventArgs e)
		{

			SelectSamplesEventArgs ev = new SelectSamplesEventArgs();
			ev.ID = Convert.ToInt32(Num_ID.Text);
			if (rdoManual.Checked)
				ev.SelectType = 1;
			if (rdoBatch.Checked)
				ev.SelectType = 0;
			if (rdoBatchOut.Checked)
				ev.SelectType = 2;
			if (SelectSampleClick != null)
				this.SelectSampleClick(this, ev);
			this.Num_ID.Focus();
		}

		private void rdo_CheckedChanged(object sender, System.EventArgs e)
		{
			if (this.rdoManual.Checked)
				lblNum_ID.Text = "Enter Label ID:";
			else
				lblNum_ID.Text = "Enter Batch Number:";
			this.Num_ID.Focus();
		}

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}


}
